package com.cncbox.service.impl;

import com.cncbox.dao.ClickLinkDao;
import com.cncbox.entity.ClickLink;
import com.cncbox.entity.NoteResult;
import com.cncbox.service.ClickLinkService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 点击链接
 * Created by songs on 2016/4/13.
 */
public class ClickLinkServiceImpl implements ClickLinkService {

    @Autowired
    private ClickLinkDao clickLinkDao;


    //添加数据
    public NoteResult addClickLink(ClickLink clickLink) throws Exception {
        NoteResult result = new NoteResult();

        Boolean addClickLink = clickLinkDao.addClickLink(clickLink);
        if (addClickLink) {
            result.setMsg("ADD_SUCCESS");
            result.setStatus(1);
        } else {
            result.setMsg("ADD_ERROR");
            result.setStatus(0);
        }
        return result;
    }

    //删除数据
    public NoteResult deleteClickLink(Integer cId) throws Exception {
        NoteResult result = new NoteResult();
        Boolean deleteClickLink = clickLinkDao.deleteClickLink(cId);
        if (deleteClickLink) {
            result.setMsg("DELETE_SUCCESS");
            result.setStatus(1);
        } else {
            result.setMsg("DELETE_ERROR");
            result.setStatus(0);
        }
        return result;
    }

    //修改数据
    public NoteResult updateClickLink(ClickLink clickLink) throws Exception {
        NoteResult result = new NoteResult();
        Boolean updateClickLink = clickLinkDao.updateClickLink(clickLink);
        if (updateClickLink) {
            result.setMsg("UPDATE_SUCCESS");
            result.setStatus(1);
        } else {
            result.setMsg("UPDATE_ERROR");
            result.setStatus(0);
        }
        return result;
    }

    //修改前查询数据
    public NoteResult queryClickLink(Integer cId) throws Exception {
        NoteResult result = new NoteResult();
        ClickLink clickLink = clickLinkDao.queryClickLink(cId);
        if (0 < clickLink.getId()) {
            result.setMsg("QUERY_SUCCESS");
            result.setStatus(1);
            result.setData(clickLink);
        } else {
            result.setMsg("QUERY_ERROR");
            result.setStatus(0);
        }
        return result;
    }

    //查询数据
    public NoteResult selectClickLink(String className) throws Exception {
        NoteResult result = new NoteResult();
        List<ClickLink> clickLinks = clickLinkDao.selectClickLink(className);
        if (0 < clickLinks.size()) {
            result.setMsg("QUERY_SUCCESS");
            result.setStatus(1);
            result.setData(clickLinks);
        } else {
            result.setMsg("QUERY_ERROR");
            result.setStatus(0);
        }
        return result;
    }
}
